﻿using Minecraft.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Minecraft.Config.Csv.CsvCom;

namespace Minecraft.Config.Csv.CsvCls
{
	public partial class Mod_Map
	{
		/// <summary>
		/// 地图坐标
		/// </summary>
		public Point3 point3
		{
			get
			{
				var strs = Place.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(m => Convert.ToInt32(m));
				return new Point3
				{
					x = strs[0],
					y = strs[1],
					z = strs[2]
				};
			}
		}

		/// <summary>
		/// 危险等级
		/// </summary>
		public int danger_Convert
		{
			get
			{
				return int.Parse(Danger);
			}
		}
		/// <summary>
		/// 显示等级
		/// </summary>
		public int level_Convert
		{
			get
			{
				return int.Parse(level);
			}
		}
		/// <summary>
		/// 是否是补给站
		/// </summary>
		public bool If_depot_Convert
		{
			get
			{
				if (If_depot == "1")
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		}

		/// <summary>
		/// 获取下一个补给站的列表（基地周围可能有多个补给站）
		/// </summary>
		/// <returns></returns>
		public List<string> GetNextDepotIdList()
		{
			return Next_depot.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
		}
		/// <summary>
		/// 宝箱生成的最大数量
		/// </summary>
		public int TreasureBoxMaxNum_Convert
		{
			get
			{
				return int.Parse(TreasureBoxMaxNum);
			}
		}

		/// <summary>
		/// 获取掉落配置信息
		/// </summary>
		/// <returns></returns>
		public List<ModMapTreasureBoxDropInfo> GetModMapTreasureBoxDropInfoList()
		{
			List<ModMapTreasureBoxDropInfo> modMapTreasureBoxDropInfoList = new List<ModMapTreasureBoxDropInfo>();
			var TreasureBoxStrs = TreasureBox.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
			int index = 0;
			foreach (var TreasureBoxStr in TreasureBoxStrs)
			{
				var strs = TreasureBoxStr.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
				modMapTreasureBoxDropInfoList.Add(new ModMapTreasureBoxDropInfo
				{
					treasureBoxItemId = strs[0],
					index = index,
					rate = int.Parse(strs[1]),
				});
				index++;
			}
			//赋值 rateMinVal 和 rateMaxVal
			for (int i = 0; i < modMapTreasureBoxDropInfoList.Count(); i++)
			{
				var modMapTreasureBoxDropInfo = modMapTreasureBoxDropInfoList[i];
				var beforeList = modMapTreasureBoxDropInfoList.Where(m => m.index < i).ToList();
				modMapTreasureBoxDropInfo.rateMinVal = beforeList.Sum(m => m.rate) + 1;
				modMapTreasureBoxDropInfo.rateMaxVal = beforeList.Sum(m => m.rate) + modMapTreasureBoxDropInfo.rate;
			}
			return modMapTreasureBoxDropInfoList;
		}

		/// <summary>
		/// 地图资源防刷上限信息列表
		/// </summary>
		/// <returns></returns>
		public List<ModMapResourceMaxNumInfo> GetModMapResourceMaxNumInfoList()
		{
			List<ModMapResourceMaxNumInfo> modMapResourceMaxNumInfoList = new List<ModMapResourceMaxNumInfo>();
			var ResourceMaxNumInfoStrs = ResourceMaxNum.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (var ResourceMaxNumInfoStr in ResourceMaxNumInfoStrs)
			{
				var items = ResourceMaxNumInfoStr.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
				modMapResourceMaxNumInfoList.Add(new ModMapResourceMaxNumInfo
				{
					itemId = items[0],
					maxNum = Convert.ToInt32(items[1])
				});
			}
			return modMapResourceMaxNumInfoList;
		}
	}
}
